<template>
  <div
    v-loading="dataListLoading"
    class="app-container"
    :element-loading-text="loadingText"
  >
    <div class="inner-container">
      <el-form ref="queryForm" :model="queryForm" class="filter-container">
        <el-form-item class="filter-item" prop="searchKey">
          <el-input
            v-model="queryForm.searchKey"
            placeholder="请输入查询条件"
            clearable
            prefix-icon="el-icon-search"
            @clear="searchCourse"
            @keyup.enter.native="searchCourse"
          ></el-input>
        </el-form-item>
        <el-form-item class="filter-item">
          <el-button type="primary" @click="searchCourse">查询</el-button>
        </el-form-item>
      </el-form>

      <div class="table-box">
        <el-table :data="dataList">
          <el-table-column
            prop="name"
            label="课程名称"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column
            prop="startDate"
            label="开始时间"
            align="center"
            show-overflow-tooltip
          >
          </el-table-column>

          <el-table-column
            prop="endDate"
            label="结束时间"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="teacherName"
            label="老师"
            align="center"
            show-overflow-tooltip
          >

          </el-table-column>
          <el-table-column
            label="操作"
            width="200"
            align="center"
          >
            <template slot-scope="scope">
              <el-tooltip content="取消选择" placement="top" effect="light">
                <el-button
                  v-if="isAuth('select:delete')"
                  type="default"
                  icon="el-icon-remove"
                  @click="deleteCourse(scope.row.id)"
                ></el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="page-container">
        <el-pagination
          :current-page="current"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="size"
          :total="totalCount"
          background
          layout="total, prev, pager, next,sizes,jumper"
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
        >
        </el-pagination>
      </div>
    </div>
    <!--    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdateCourse" @refreshDataList="refreshDataList"></add-or-update>-->
  </div>
</template>

<script>
import { $gc } from 'gc-starter-ui-plus'
// import addOrUpdate from './addOrUpdate'

export default {
  name: 'Course',
  // components: { addOrUpdate },
  mixins: [$gc.mixins.pageMixins],
  data() {
    return {
      dataListLoading: false,
      loadingText: '',
      addOrUpdateVisible: false,
      // 表单查询
      queryForm: {
        searchKey: ''
      },
      // 表格数据
      dataList: [],
      dataForm: {
        id: undefined,
        courseId: '',
        studentId: ''
      }
    }
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      this.$get('/course/myCourse', {
        current: this.current,
        size: this.size,
        searchKey: this.queryForm.searchKey || ''
      }).then(data => {
        this.dataList = data.list
      })
    },
    // 刷新
    refreshDataList() {
      this.queryForm.searchKey = ''
      this.searchCourse()
    },
    // 查询
    searchCourse() {
      this.current = 1
      this.getDataList()
    },
    // 新增或者修改
    addOrUpdate(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs['addOrUpdateCourse'].init(id)
      })
    },
    //  删除
    deleteCourse(id) {
      this.$confirm(`确定进行取消选中操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$del(`/select/${id}`).then(data => {
          this.$message.success('取消选中操作成功')
          this.getDataList()
        }).catch(e => {})
      })
    }
  }
}
</script>
